﻿using System;
using System.Threading;
using System.Windows.Forms;

namespace Marmat.Forms
{
    internal partial class PromptForm : Form
    {
        public PromptForm()
        {
            InitializeComponent();
        }

        private bool closing = false;

        private void PromptForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!closing)
                e.Cancel = true;
            closing = true;
            this.Timer1.Interval = 10;
            this.Timer1.Start();
        }

        /// <summary>
        /// 获取一个值，该值指示显示窗口时是否激活它。
        /// </summary>
        protected override bool ShowWithoutActivation => true;

        private void Timer1_Tick(object sender, EventArgs e)
        {
            int height = SystemInformation.WorkingArea.Height; // 获取屏幕的高度
            if (this.Top < height)
                this.Top += 5;
            else
                this.Close();
        }

        internal void Start(int interval)
        {
            this.timer2.Interval = interval;
            this.timer2.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}